package logic

import (
	"context"
	"four/sss/weeekapi/internal/svc"
	"four/sss/weeekapi/internal/types"
	"four/sss/weeekrpc/weeekrpcclient"
	"github.com/zeromicro/go-zero/core/logx"
)

type VipLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewVipLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VipLogic {
	return &VipLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *VipLogic) Vip(req *types.VipRequest) (resp *types.VipResponse, err error) {
	// todo: add your logic here and delete this line
	userid := req.Userid
	var r types.VipResponse
	r.VipLv = 0
	r.Code = -1
	res, err := l.svcCtx.WeekRpc.Vip(l.ctx, &weeekrpcclient.VipRequest{
		Userid: int64(userid),
	})
	if err != nil {
		r.Msg = err.Error()
		return &r, nil
	}
	r.VipLv = int(res.VipLv)
	r.Code = 200
	r.Msg = "VIP充值成功"
	return &r, nil
}
